<?php
namespace app\common\model;


use think\Db;
use think\Model;

class Refund extends Model{


    protected $table = "jiujiu_order_refund";


    public function saveRefund($data,$img,$uid){
        $order = model('order')->where('id',$data['orderId'])->find();

        if($img){
            $data['img'] = upload($img);
        }
        else{
            $data['img'] = '';
        }
        $data['refundFee'] =  $data['refundFee'] * 100;
        $data['refundStatus'] =  'wait';
        $data['uid'] =  $uid;
        $data['shopId'] =  $order->shopId;
        $data['productId'] =  $order->productId;
        $refund = $this->where('orderId',$data['orderId'])->find();
        if($refund){
            $this->where('orderId',$data['orderId'])->update($data);
            $id = $refund->id;
        }
        else{
            $data['createTime'] = time();
            $id = $this->insertGetId($data);
        }
        if($data['refundType'] == '退货退款'){
            $order->status2 = 4;
            $order->save();
        }
        if($data['refundType'] == '仅退款'){
            $order->status2 = 5;
            $order->save();
        }
        return $id;
    }



}